From d3874d09189543d3207512384de1eb40b8e40ec5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 7 Jun 2006 01:07:20 +0000 Subject: [PATCH] =?utf8?q?Bug=20337603=20=E2=80=93=20Possible=20off-by-one?= =?utf8?q?=20in?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-06-06 Behdad Esfahbod Bug 337603 – Possible off-by-one in gdk_pango_layout_line_get_clip_region * gdk/gdkpango.c (gdk_pango_layout_line_get_clip_region): Correct rounding of rect members. Improved docs. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ gdk/gdkpango.c | 24 +++++++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c423ca4d6..fdfaf9d354 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-06-06 Behdad Esfahbod + + Bug 337603 – Possible off-by-one in + gdk_pango_layout_line_get_clip_region + + * gdk/gdkpango.c (gdk_pango_layout_line_get_clip_region): Correct + rounding of rect members. Improved docs. + 2006-06-06 Matthias Clasen * gtk/gtkicontheme.c: Small optimization diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 3c423ca4d6..fdfaf9d354 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2006-06-06 Behdad Esfahbod + + Bug 337603 – Possible off-by-one in + gdk_pango_layout_line_get_clip_region + + * gdk/gdkpango.c (gdk_pango_layout_line_get_clip_region): Correct + rounding of rect members. Improved docs. + 2006-06-06 Matthias Clasen * gtk/gtkicontheme.c: Small optimization diff --git a/gdk/gdkpango.c b/gdk/gdkpango.c index 34df537f1b..d054de2717 100644 --- a/gdk/gdkpango.c +++ b/gdk/gdkpango.c @@ -1238,6 +1238,11 @@ gdk_pango_attr_embossed_new (gboolean embossed) * contained inside the line. This is to draw the selection all the way * to the side of the layout. However, the clip region is in line coordinates, * not layout coordinates. + * + * Note that the regions returned correspond to logical extents of the text + * ranges, not ink extents. So the drawn line may in fact touch areas out of + * the clip region. The clip region is mainly useful for highlightling parts + * of text, such as when text is selected. * * Return value: a clip region containing the given ranges **/ @@ -1287,12 +1292,16 @@ gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line, for (j = 0; j < n_pixel_ranges; j++) { GdkRectangle rect; + int x_off, y_off; - rect.x = x_origin + pixel_ranges[2*j] / PANGO_SCALE - logical_rect.x / PANGO_SCALE; - rect.y = y_origin - (baseline / PANGO_SCALE - logical_rect.y / PANGO_SCALE); - rect.width = (pixel_ranges[2*j + 1] - pixel_ranges[2*j]) / PANGO_SCALE; - rect.height = logical_rect.height / PANGO_SCALE; - + x_off = PANGO_PIXELS (pixel_ranges[2*j] - logical_rect.x); + y_off = PANGO_PIXELS (baseline - logical_rect.y); + + rect.x = x_origin + x_off; + rect.y = y_origin - y_off; + rect.width = PANGO_PIXELS (pixel_ranges[2*j + 1] - logical_rect.x) - x_off; + rect.height = PANGO_PIXELS (baseline - logical_rect.y + logical_rect.height) - y_off; + gdk_region_union_with_rect (clip_region, &rect); } @@ -1316,6 +1325,11 @@ gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line, * you would pass to gdk_draw_layout_line(). @index_ranges should contain * ranges of bytes in the layout's text. * + * Note that the regions returned correspond to logical extents of the text + * ranges, not ink extents. So the drawn line may in fact touch areas out of + * the clip region. The clip region is mainly useful for highlightling parts + * of text, such as when text is selected. + * * Return value: a clip region containing the given ranges **/ GdkRegion* -- 2.30.2